/*
                    Pushbutton Class Implementation
*/
#include "Pushbutton.h"

Pushbutton::Pushbutton()
{
    Image = NULL;
    ImageClicked = NULL;
    ImageDisabled = NULL;

    Position = Point(0,0);

    iWidth = 0;
    iHeight = 0;

    bClicked = false;
    bVisible = true;
    bEnabled = true;
    bPushed = false;

    strText = "";
}

Pushbutton::~Pushbutton()
{

}

int Pushbutton::HandleMouseUp(int iMouseX, int iMouseY)
{
    if (bClicked == true)
    {
        bClicked = false;

        if (bPushed == true)
        {
            bPushed = false;
        }
        else
        {
            bPushed = true;
        }

        return 1;
    }

    return 0;
}

int Pushbutton::BlitToFrame(SDL_Surface *surface, Point FramePosition)
{
    if (bVisible == true)
    {
        SDL_Rect dest;
        dest.x = static_cast<int>(Position.x) + static_cast<int>(FramePosition.x);
        dest.y = static_cast<int>(Position.y) + static_cast<int>(FramePosition.y);

        if (bClicked == true || bPushed == true)
        {
            SDL_BlitSurface(ImageClicked, NULL, surface, &dest);
        }
        else if (bEnabled == false)
        {
            SDL_BlitSurface(ImageDisabled, NULL, surface, &dest);
        }
        else
        {
            SDL_BlitSurface(Image, NULL, surface, &dest);
        }

        lblButtonText.BlitToFrame(surface, FramePosition);
    }

    return 0;
}

bool Pushbutton::getPushed()
{
    return bPushed;
}

void Pushbutton::setPushed(const bool& bNewPushed)
{
    bPushed = bNewPushed;
}
